package com.kasinf.sample;

import com.xxl.mq.core.XxlMqHelper;
import com.xxl.mq.core.consumer.annotation.XxlMq;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author kaiser
 * @date 2025/6/1
 */
@Slf4j
@Component
public class SimpleXxlMq {
    @XxlMq("topic_sample")
    public void consume() {
        // consume message
        long messageId = XxlMqHelper.getMessageId();
        String messageData = XxlMqHelper.getMessageData();
        log.info("topic[{}] consume message, messageId: {}, messageData: {}", "topic_sample", messageId, messageData);

        // set consume result
        XxlMqHelper.consumeSuccess();
    }

    @XxlMq("topic_sample_02")
    public void consume02() {
        log.info("topic[{}] consume message, messageId: {}, messageData: {}", "topic_sample_02", XxlMqHelper.getMessageId(), XxlMqHelper.getMessageData());
    }

    @XxlMq("topic_sample_03")
    public void consume03() {
        log.info("topic[{}] consume message, messageId: {}, messageData: {}", "topic_sample_03", XxlMqHelper.getMessageId(), XxlMqHelper.getMessageData());
    }

    @XxlMq("topic_sample_04")
    public void consume04() {
        log.info("topic[{}] consume message, messageId: {}, messageData: {}", "topic_sample_04", XxlMqHelper.getMessageId(), XxlMqHelper.getMessageData());
    }

    @XxlMq("topic_sample_05")
    public void consume05() {
        log.info("topic[{}] consume message, messageId: {}, messageData: {}", "topic_sample_05", XxlMqHelper.getMessageId(), XxlMqHelper.getMessageData());
    }

    @XxlMq("topic_sample_06")
    public void consume06() {
        log.info("topic[{}] consume message, messageId: {}, messageData: {}", "topic_sample_06", XxlMqHelper.getMessageId(), XxlMqHelper.getMessageData());

        XxlMqHelper.consumeFail("consumer fail~");
    }

    @XxlMq("topic_sample_07")
    public void consume07() {
        log.info("topic[{}] consume message, messageId: {}, messageData: {}", "topic_sample_07", XxlMqHelper.getMessageId(), XxlMqHelper.getMessageData());
    }
}
